package controller;


import bean.User;
import org.springframework.ui.Model;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import until.ImageUtils;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 赵海军
 * @createTime 2020-01-16 17:49
 */

public class UserController {
    @RequestMapping(path = "/addPhoto.do", method = RequestMethod.POST)
    public Map<String, Object> addPhoto( HttpServletRequest request, MultipartFile pictureFile) {
        Map<String, Object> map = new HashMap<String, Object>();
        // 得到上传图片的地址

        String imgPath;
      try{
            //ImageUtils为之前添加的工具类
            imgPath = ImageUtils.upload(request, pictureFile);
            if (imgPath != null) {
                // 将上传图片的地址封装到实体类
                map.put("imgPath",imgPath);
                System.out.println("-----------------图片上传成功！");
            } else {
                System.out.println("-----------------图片上传失败！");
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            System.out.println("----------------图片上传失败！");
        }
              return  map;
    }}



